<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * 附件管理模型
 * @author wb_wenjie.wuwj
 * @version 1.0.1 2013-2-17
 */
class Attachment_m extends MY_Model
{
	function __construct()
	{
		parent::__construct();
	}
	
	/**
	 * 查询附件
	 * @param $where 查询条件
	 * @return array 返回查询结果集
	 */
	function get_attachment($where)
	{
		if(! empty($where))
		{
			$this->db->select('*');
			$this->db->where($where);
			$query = $this->db->get('attachment');
			return $query->result_array();
		}
		else
		{
			return FALSE;
		}
	}
	
	/**
	 * 删除附件，只将表记录中的bindid设置为0
	 * @param array $manager_id 删除的条件数组
	 * @param boolean $delete_file 是否删除附件文件
	 */
	function delete_attachment($where, $delete_file = FALSE)
	{
		// @TODO 删除对应的附件文件
		if (TRUE == $delete_file)
		{
			$this->delete_file($where);
		}
		return $this->delete_record('attachment', $where);
	}
	
	/**
	 * 根据相应条件更新附件信息
	 * @param array $where 条件数组
	 * @param array $data 要更新的附件信息
	 * @return boolean 
	 */
	function update_attachment($where, $data)
	{
		return $this->update('attachment', $where, $data);
	}
	
	/**
	 * 添加附件
	 * @param array $manager 附件信息数组
	 * @return boolean 失败返回false
	 */
	function insert_attachment($attachment)
	{
		return $this->insert('attachment', $attachment);
	}

	/* (non-PHPdoc)
	 * @see MY_Model::count_all_results()
	 */
	function count_all_results($where)
	{
		return parent::count_all_results('attachment', $where);
	}
	
	function delete_file($url)
	{
		// @TODO 删除附件
		return TRUE;
	}
}

/* End of file attachment_m.php */
/* Location: ./application/models/attachment_m.php */